package com.carbon.trade.controller;

import com.carbon.common.api.Paging;
import com.carbon.domain.common.ApiResult;
import com.carbon.trade.common.BaseController;
import com.carbon.trade.param.CarbonTradePriceQueryParam;
import com.carbon.trade.service.CarbonTradePriceService;
import com.carbon.trade.vo.CarbonTradePriceQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 碳交易询报价管理 前端控制器
 * </p>
 *
 * @author system
 * @since 2024-12-19
 */
@Slf4j
@RestController
@RequestMapping("/carbonTradePrice")
@Api(value = "碳交易询报价管理模块", tags = {"碳交易询报价管理模块"})
public class CarbonTradePriceController extends BaseController {

    @Autowired
    private CarbonTradePriceService carbonTradePriceService;

    /**
     * 测试接口
     */
    @GetMapping("/test")
    @ApiOperation(value = "测试接口", notes = "测试接口")
    public ApiResult<String> test() {
        log.info("CarbonTradePriceController test method called");
        return ApiResult.ok("CarbonTradePriceController is working!");
    }

    /**
     * 分页查询碳交易询报价管理
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "分页查询碳交易询报价管理", notes = "分页查询碳交易询报价管理")
    public ApiResult<Paging<CarbonTradePriceQueryVo>> getPageList(@RequestBody CarbonTradePriceQueryParam queryParam) {
        try {
            log.info("查询碳交易询报价管理参数: {}", queryParam);
            if (carbonTradePriceService == null) {
                log.error("carbonTradePriceService is null!");
                return ApiResult.fail("Service not available");
            }
            Paging<CarbonTradePriceQueryVo> paging = carbonTradePriceService.getPageList(queryParam);
            return ApiResult.ok(paging);
        } catch (Exception e) {
            log.error("查询碳交易询报价管理失败", e);
            return ApiResult.fail("查询失败: " + e.getMessage());
        }
    }

    /**
     * 根据ID获取详情
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取详情", notes = "根据ID获取碳交易询报价管理详情")
    public ApiResult<CarbonTradePriceQueryVo> getInfo(@PathVariable("id") Long id) {
        try {
            log.info("获取碳交易询报价管理详情ID: {}", id);
            CarbonTradePriceQueryVo vo = carbonTradePriceService.getInfo(id);
            return ApiResult.ok(vo);
        } catch (Exception e) {
            log.error("获取碳交易询报价管理详情失败", e);
            return ApiResult.fail("获取详情失败: " + e.getMessage());
        }
    }

    /**
     * 意向成交
     */
    @PostMapping("/intendedTransaction")
    @ApiOperation(value = "意向成交", notes = "意向成交")
    public ApiResult<Boolean> intendedTransaction(@RequestBody Object data) {
        try {
            log.info("意向成交参数: {}", data);
            boolean result = carbonTradePriceService.intendedTransaction(data);
            return ApiResult.ok(result);
        } catch (Exception e) {
            log.error("意向成交失败", e);
            return ApiResult.fail("意向成交失败: " + e.getMessage());
        }
    }
}